import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

from sklearn import linear_model

pd.set_option('display.max_columns', None)
# pd.set_option('display.max_rows', None)
pd.set_option('max_colwidth', 999)

plt.rcParams['font.sans-serif'] = ['SimHei']

df = pd.read_csv('000001.csv', encoding='GBK')
data = df.to_numpy()[:, [0, 3]]
data = data[-1::-1]

data = data[-300:]

date = data[:, 0]
index = data[:, 1].astype(float)
x = [[i] for i in range(len(index))]
x = np.array(x)

reg = linear_model.LinearRegression()
reg.fit(X=x, y=index)
print(reg.coef_)


plt.figure(figsize=(12, 4))
plt.plot(range(len(date)), index, linewidth=1)
plt.gca().set_xticklabels(date)
plt.show()



